//
//  ABTabbar.swift
//  hEhL
//
//  Created by 本 on 16/5/7.
//  Copyright © 2016年 本. All rights reserved.
//

import UIKit


class ABTabbar: UITabBar {
     lazy var plusButton : UIButton =  {
        let btn = UIButton.init(type: UIButtonType.Custom)
        btn.setImage(UIImage(named: "icon_tabBar_speedy_menu_selected"), forState: .Normal)
        btn.setImage(UIImage(named: "icon_tabBar_speedy_menu"), forState: .Selected)
        btn.sizeToFit()
        self.addSubview(btn)
        return btn
        
    }()
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
    
        let count = (items?.count)! + 1
        var x : CGFloat = 0.0
        let y : CGFloat = 0.0
        let w : CGFloat = bounds.size.width / CGFloat(count)
        let h : CGFloat = bounds.size.height

        var num = 0
        for item in self.subviews{
            if !item.isKindOfClass(NSClassFromString("UITabBarButton")!) {continue}
            if num == 2 {num = 3}
            x = CGFloat(num) * w
            item.frame = CGRectMake(x, y, w, h)
            num = num + 1
            
            
           
            
        }
        
        self.plusButton.center = CGPointMake(self.frame.size.width * 0.5 ,self.frame.size.height * 0.5)
        
        
    }
    
}
